package com.itheima.service.impl;

import com.itheima.domin.vo.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.domin.entity.DegreeCount;
import com.itheima.domin.entity.GenderCount;
import com.itheima.domin.entity.JobCount;
import com.itheima.domin.entity.StudentCount;
import com.itheima.domin.pojo.Log;
import com.itheima.domin.query.LogQuery;
import com.itheima.domin.vo.JobOption;
import com.itheima.domin.vo.StudentOption;
import com.itheima.mapper.ReportMapper;
import com.itheima.service.ReportService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**统计人数业务处理
 * @Author:上官徵羽
 * @Date: 2025/07/14 16:32
 * @Description TODO 今日内容:
 */
@Service
public class ReportServiceImpl implements ReportService {
    private static final Logger log = LoggerFactory.getLogger(ReportServiceImpl.class);
    @Autowired
    private ReportMapper reportMapper;

    /** 统计各个岗位人数 */
    @Override
    public JobOption getEmpJobDate() {
        List<JobCount> jobOption = reportMapper.reportJobIsNum();
        List<String> jobList = jobOption.stream().map(JobCount::getPos).toList();
        List<Long> dataList = jobOption.stream().map(JobCount::getNum).toList();
        return new JobOption(jobList,dataList);
    }

    /** 统计男女员工人数 */
    @Override
    public List<GenderCount> getEmpGenderData() {
        return reportMapper.getEmpGenderData();
    }

    /** 统计各个学历人数 */
    @Override
    public List<DegreeCount> getStudentDegreeData() {
        List<DegreeCount> degreeData = reportMapper.getDegreeData();
        log.info("ReportServiceImpl getStudentDegreeData: 学员学历:{}",degreeData);
        return degreeData;
    }

    /** 统计各个班级人数 */
    @Override
    public StudentOption getStudentCountData() {
        List<StudentCount> studentCountData = reportMapper.getStudentCountData();
        List<String> clazzList = studentCountData.stream().map(StudentCount::getClazzName).toList();
        List<Long> dataList = studentCountData.stream().map(StudentCount::getStudentNum).toList();
        return new StudentOption(clazzList,dataList);
    }

    /** 日志列表分页查询 */
    @Override
    public PageResult<Log> logInfo(LogQuery logQuery) {
        PageHelper.startPage(logQuery.getPage(),logQuery.getPageSize());
        Page<Log> p = reportMapper.logInfo(logQuery);
        return new PageResult<>(p.getTotal(),p.getResult());
    }

    /** 监听记录日志 */
    @Override
    public void addLog(Log log) {
        reportMapper.addLog(log);
    }
}
